<template>
	<view style="width: 100%; ">
		<view v-for="(item, index) in questions" :key="item.id" style=" margin: 20rpx ; ">
			<view style="font-size:30rpx">{{ index + 1 }}.{{ item.name }}
				<span v-if="item.type == 1" style="font-size:30rpx">(选择题)</span>
				<span v-if="item.type == 2" style="font-size:30rpx">(判断题)</span>
				<span v-if="item.type == 3" style="font-size:30rpx">(简答题)</span>
			</view>
			<view v-if="item.type == 1" style=" margin: 20rpx ; ">
				<uni-data-checkbox v-model="item['studentAnswear']"
					:localdata="[{text:item.a,value:'A'},{text:item.b,value:'B'},{text:item.c,value:'C'},{text:item.d,value:'D'}]">
				</uni-data-checkbox>

			</view>
			<view v-if="item.type == 2" style=" margin: 20rpx ; ">
				<uni-data-checkbox v-model="item['studentAnswear']"
					:localdata="[{text:'是',value:'是'},{text:'否',value:'否'}]">
				</uni-data-checkbox>
			</view>
			<view v-if="item.type == 3" style=" margin: 20rpx ; ">
				<uni-easyinput type="textarea" v-model="item['studentAnswear']" placeholder="输入答案" />
			</view>

		</view>
		<view style=" padding-bottom: 20rpx ;">
			<navigator url="/pages/index/index" style="margin: 10rpx;" open-type="switchTab"
				hover-class="other-navigator-hover">
				<button style="margin: 10rpx;" type="primary" @click="submitPapered">提交</button>
				<button style="margin: 10rpx;" type="primary">取消</button>
			</navigator>
			<!-- <button  style="margin: 10rpx;" type="primary" @click="toBack">取消</button> -->
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {

				questions: [],
				examId: null,
				user: {},
			}
		},
		onLoad(option) {
			this.examId = option.examId;
			this.user = uni.getStorageSync('user');

			wx.setNavigationBarTitle({
				title: option.examName
			});

			this.request({
				url: `/paper/view/${option.paperId}`

			}).then(res => {
				this.questions = res.data;
			})
		},
		methods: {
			submitPapered() {
				this.request({
					url: '/studentPaper',
					method: 'POST',
					data: {
						examId: this.examId,
						userId: this.user.id,
						paper: JSON.stringify(this.questions)
					}
				}).then(res => {
					if (res.code === '0') {
						uni.showToast({
							title: '提交成功'
						});
						// uni.navigateTo({
						// 	url: '/pages/index/index'
						// });
					}
				});
			},
			// toBack(){
			// 	console.log('112121');
			// 	uni.navigateTo({
			// 		url: '/pages/index/index'
			// 	});
			// 	uni.navigateTo({
			// 		url: 'pages/new/new'
			// 	});
			// },
		}
	}
</script>

<style>

</style>
